package com.caiyouxi.boss.buser.controller;


import com.caiyouxi.boss.buser.model.SysUserProfileBean;
import com.caiyouxi.boss.buser.model.UserListInfoBean;
import com.caiyouxi.boss.buser.service.SysUserProfileService;
import com.caiyouxi.common.bean.ResData;
import com.caiyouxi.common.control.BaseController;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Created by Administrator on 2017/10/20.
 */
@RestController
@RequestMapping("/boss/user")
public class SysUserProfileController extends BaseController {


    private Logger logger = Logger.getLogger(SysUserProfileController.class);

    @Autowired
    private SysUserProfileService userProfileService;

    /**
     * 获取用户权限
     * @param userBean
     * @return
     */
    @RequestMapping("/get_rights")
    public ResData get_user_rights(HttpServletRequest request, HttpServletResponse response,   SysUserProfileBean userBean){
        logger.info("get_rights");
        return userProfileService.get_sys_rights_id(userBean);
    }

    /**
     * 新增用户
     */
    @RequestMapping("/create")
    public ResData add_user(HttpServletRequest request, HttpServletResponse response, @RequestBody SysUserProfileBean sysUserProfileBean){

        logger.info("=============================== 新增用户 ================================");
        return userProfileService.add_user(sysUserProfileBean);
    }

    /**
     * 用户详情
     */
    @RequestMapping("/info")
    public ResData get_user_info(HttpServletRequest request, HttpServletResponse response,  @RequestBody SysUserProfileBean bean){

        logger.info("=============================== 详情 ================================");
        return userProfileService.get_user_info(bean.getId());
    }

    /**
     * 获取用户列表
     */
    @RequestMapping("/list")
     public ResData get_user_list(HttpServletRequest request, HttpServletResponse response, @RequestBody SysUserProfileBean bean){

         logger.info("=============================== 用户列表 ================================");
         return userProfileService.get_user_list(bean);
     }

    /**
     * 更新用户状态
     */
    @RequestMapping("/update")
    public ResData update_user(HttpServletRequest request, HttpServletResponse response, @RequestBody SysUserProfileBean sysUserProfileBean){
        logger.info("=============================== 更改用户状态 ================================");
        return userProfileService.updateUserProfile(sysUserProfileBean);
    }

    /**
     * 编辑用户
     */
    @RequestMapping("/edite")
    public ResData edite_user(HttpServletRequest request, HttpServletResponse response, @RequestBody SysUserProfileBean bean){
        logger.info("=============================== 更改用户状态 ================================");
        return userProfileService.editeUserProfile(bean);
    }

    /**
     * 删除用户
     */
    @RequestMapping("/delete")
    public ResData delete_user(HttpServletRequest request, HttpServletResponse response, @RequestBody SysUserProfileBean bean){

        logger.info("=============================== 删除用户 ================================");
        return userProfileService.delete_user(bean);
    }

    /**
     * 查询用户拥有权限
     */
    @RequestMapping("/to_index")
    public ResData to_index(HttpServletRequest request, HttpServletResponse response,@RequestBody  SysUserProfileBean sysUserProfileBean){
        return userProfileService.to_index(sysUserProfileBean.getId());
    }



    /**
     * 条件查询用户信息
     */
    @RequestMapping("/get_user_info_list")
    public ResData get_user_info_list(HttpServletRequest request, HttpServletResponse response,@RequestBody  UserListInfoBean bean){
      ResData resData =   userProfileService.get_user_info_list(bean);
        return resData;
    }


    /**
     * 用户基本详情
     */
    @RequestMapping("/get_user_profile_info")
    public ResData get_user_profile_info(HttpServletRequest request, HttpServletResponse response,@RequestBody  UserListInfoBean bean){
        ResData resData =   userProfileService.get_user_profile_info(bean);
        return resData;
    }


    /**
     * 冻结用户
     */
    @RequestMapping("/blocking_user")
    public ResData blocking_user(HttpServletResponse response, HttpServletRequest request,@RequestBody UserListInfoBean bean){
        return userProfileService.blocking_user(bean);
    }


}
